home *** CD-ROM | disk | FTP | other *** search
/ Risc World 5 / Risc World 5.iso / SOFTWARE / Issue3 / Games / xrick / !xrick / src / c / maps < prev    next >
Text File  |  2004-06-24  |  5KB  |  217 lines

  1. /*
  2.  * xrick/src/maps.c
  3.  *
  4.  * Copyright (C) 1998-2002 BigOrno (bigorno@bigorno.net). All rights reserved.
  5.  *
  6.  * The use and distribution terms for this software are contained in the file
  7.  * named README, which can be found in the root of this distribution. By
  8.  * using this software in any fashion, you are agreeing to be bound by the
  9.  * terms of this license.
  10.  *
  11.  * You must not remove this notice, or any other, from this software.
  12.  */
  13.  
  14. /*
  15.  * NOTES
  16.  *
  17.  * A map is composed of submaps, which in turn are composed of rows of
  18.  * 0x20 tiles. map_map contains the tiles for the current portion of the
  19.  * current submap, i.e. a little bit more than what appear on the screen,
  20.  * but not the whole submap.
  21.  *
  22.  * map_frow is map_map top row within the submap.
  23.  *
  24.  * Submaps are stored as arrays of blocks, each block being a 4x4 tile
  25.  * array. map_submaps[].bnum points to the first block of the array.
  26.  *
  27.  * Before a submap can be played, it needs to be expanded from blocks
  28.  * to map_map.
  29.  */
  30.  
  31. #include "system.h"
  32. #include "game.h"
  33. #include "maps.h"
  34. #include "debug.h"
  35.  
  36. #include "ents.h"
  37. #include "draw.h"
  38. #include "screens.h"
  39. #include "e_sbonus.h"
  40.  
  41. /*
  42.  * global vars
  43.  */
  44. U8 map_map[0x2C][0x20];
  45. U8 map_eflg[0x100];
  46. U8 map_frow;
  47. U8 map_tilesBank;
  48.  
  49.  
  50. /*
  51.  * prototypes
  52.  */
  53. static void map_eflg_expand(U8);
  54.  
  55.  
  56. /*
  57.  * Fill in map_map with tile numbers by expanding blocks.
  58.  *
  59.  * add map_submaps[].bnum to map_frow to find out where to start from.
  60.  * We need to /4 map_frow to convert from tile rows to block rows, then
  61.  * we need to *8 to convert from block rows to block numbers (there
  62.  * are 8 blocks per block row). This is achieved by *2 then &0xfff8.
  63.  */
  64. void
  65. map_expand(void)
  66. {
  67.   U8 i, j, k, l;
  68.   U8 row, col;
  69.   U16 pbnum;
  70.  
  71.   pbnum = map_submaps[game_submap].bnum + ((2 * map_frow) & 0xfff8);
  72.   row = col = 0;
  73.  
  74.   for (i = 0; i < 0x0b; i++) {  /* 0x0b rows of blocks */
  75.     for (j = 0; j < 0x08; j++) {  /* 0x08 blocks per row */
  76.       for (k = 0, l = 0; k < 0x04; k++) {  /* expand one block */
  77.     map_map[row][col++] = map_blocks[map_bnums[pbnum]][l++];
  78.     map_map[row][col++] = map_blocks[map_bnums[pbnum]][l++];
  79.     map_map[row][col++] = map_blocks[map_bnums[pbnum]][l++];
  80.     map_map[row][col]   = map_blocks[map_bnums[pbnum]][l++];
  81.     row += 1; col -= 3;
  82.       }
  83.       row -= 4; col += 4;
  84.       pbnum++;
  85.     }
  86.     row += 4; col = 0;
  87.   }
  88. }
  89.  
  90.  
  91. /*
  92.  * Initialize a new submap
  93.  *
  94.  * ASM 0cc3
  95.  */
  96. void
  97. map_init(void)
  98. {
  99.   /*sys_printf("xrick/map_init: map=%#04x submap=%#04x\n", g_map, game_submap);*/
  100. #ifdef GFXPC
  101.   draw_filter = 0xffff;
  102.   map_tilesBank = (map_submaps[game_submap].page == 1) ? 3 : 2;
  103. #endif
  104. #ifdef GFXST
  105.   map_tilesBank = (map_submaps[game_submap].page == 1) ? 2 : 1;
  106. #endif
  107.   map_eflg_expand((map_submaps[game_submap].page == 1) ? 0x10 : 0x00);
  108.   map_expand();
  109.   ent_reset();
  110.   ent_actvis(map_frow + MAP_ROW_SCRTOP, map_frow + MAP_ROW_SCRBOT);
  111.   ent_actvis(map_frow + MAP_ROW_HTTOP, map_frow + MAP_ROW_HTBOT);
  112.   ent_actvis(map_frow + MAP_ROW_HBTOP, map_frow + MAP_ROW_HBBOT);
  113. }
  114.  
  115.  
  116. /*
  117.  * Expand entity flags for this map
  118.  *
  119.  * ASM 1117
  120.  */
  121. void
  122. map_eflg_expand(U8 offs)
  123. {
  124.   U8 i, j, k;
  125.  
  126.   for (i = 0, k = 0; i < 0x10; i++) {
  127.     j = map_eflg_c[offs + i++];
  128.     while (j--) map_eflg[k++] = map_eflg_c[offs + i];
  129.   }
  130. }
  131.  
  132.  
  133. /*
  134.  * Chain (sub)maps
  135.  *
  136.  * ASM 0c08
  137.  * return: TRUE/next submap OK, FALSE/map finished
  138.  */
  139. U8
  140. map_chain(void)
  141. {
  142.   U16 c, t;
  143.  
  144.   game_chsm = 0;
  145.   e_sbonus_counting = FALSE;
  146.  
  147.   /* find connection */
  148.   c = map_submaps[game_submap].connect;
  149.   t = 3;
  150.  
  151.   IFDEBUG_MAPS(
  152.     sys_printf("xrick/maps: chain submap=%#04x frow=%#04x .connect=%#04x %s\n",
  153.            game_submap, map_frow, c,
  154.            (game_dir == LEFT ? "-> left" : "-> right"));
  155.   );
  156.  
  157.   /*
  158.    * look for the first connector with compatible row number. if none
  159.    * found, then panic
  160.    */
  161.   for (c = map_submaps[game_submap].connect; ; c++) {
  162.     if (map_connect[c].dir == 0xff)
  163.       sys_panic("(map_chain) can not find connector\n");
  164.     if (map_connect[c].dir != game_dir) continue;
  165.     t = (ent_ents[1].y >> 3) + map_frow - map_connect[c].rowout;
  166.     if (t < 3) break;
  167.   }
  168.  
  169.   /* got it */
  170.   IFDEBUG_MAPS(
  171.     sys_printf("xrick/maps: chain frow=%#04x y=%#06x\n",
  172.            map_frow, ent_ents[1].y);
  173.     sys_printf("xrick/maps: chain connect=%#04x rowout=%#04x - ",
  174.            c, map_connect[c].rowout);
  175.     );
  176.  
  177.   if (map_connect[c].submap == 0xff) {
  178.     /* no next submap - request next map */
  179.     IFDEBUG_MAPS(
  180.       sys_printf("chain to next map\n");
  181.       );
  182.     return FALSE;
  183.   }
  184.   else  {
  185.     /* next submap */
  186.     IFDEBUG_MAPS(
  187.       sys_printf("chain to submap=%#04x rowin=%#04x\n",
  188.          map_connect[c].submap, map_connect[c].rowin);
  189.       );
  190.     map_frow = map_frow - map_connect[c].rowout + map_connect[c].rowin;
  191.     game_submap = map_connect[c].submap;
  192.     IFDEBUG_MAPS(
  193.       sys_printf("xrick/maps: chain frow=%#04x\n",
  194.          map_frow);
  195.       );
  196.     return TRUE;
  197.   }
  198. }
  199.  
  200.  
  201. /*
  202.  * Reset all marks, i.e. make them all active again.
  203.  *
  204.  * ASM 0025
  205.  *
  206.  */
  207. void
  208. map_resetMarks(void)
  209. {
  210.   U16 i;
  211.   for (i = 0; i < MAP_NBR_MARKS; i++)
  212.     map_marks[i].ent &= ~MAP_MARK_NACT;
  213. }
  214.  
  215.  
  216. /* eof */
  217.